import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/mine/vehilce_list/auth_application_list/bind_apply_item.dart';
import 'package:inmotion_pro/pages/models/auth_application_model.dart';
import 'package:inmotion_pro/pages/others/custom_view/others/refresh_view.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

import 'controller.dart';

class BindApplyToMeView extends BaseGetView<BindApplyToMeController> {
  BindApplyToMeView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => KeepAliveWrapper(
        child: Container(
          color: Colors.black.withOpacity(0.6),
          child: LxRefreshView(
            onRefresh: () => controller.onRefresh(),
            onLoadMore: () => controller.onLoadMore(),
            enablePullUp: false,
            child: controller.applicationList.isEmpty
                ? LxEmptyView(emptyMessage: local.no_data_available)
                : ListView.separated(
                    itemCount: controller.applicationList.length,
                    itemBuilder: (BuildContext context, int index) {
                      AuthApplicationModel bindApplyModel =
                          controller.applicationList[index];
                      return Padding(
                        padding: EdgeInsets.only(
                          top: CONTENT_MARGIN,
                          left: CONTENT_MARGIN,
                          right: CONTENT_MARGIN,
                        ),
                        child: BindApplyItem(
                          applyType: BindApplyType.toMe,
                          bindApplyModel: bindApplyModel,
                          onAccept: () {
                            controller.handleApplicationOnTap(
                                bindApplyModel, true);
                          },
                          onReject: () {
                            controller.handleApplicationOnTap(
                                bindApplyModel, false);
                          },
                        ),
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return const SizedBox.shrink();
                    },
                  ),
          ),
        ),
      ),
    );
  }
}
